#include "tinyxml2.h"
#include <iostream>
#include <regex>
#include <string>

using namespace tinyxml2;
using std::cout;
using std::endl;
using std::regex;
using std::string;


void test()
{
    XMLDocument doc;
	doc.LoadFile( "coolshell.xml" );//加载文件
    if(doc.ErrorID())
    {
        std::cerr << "LoadFile error" << endl;
        return;
    }

    XMLElement* root = doc.FirstChildElement( "rss" )
        ->FirstChildElement("channel")
        ->FirstChildElement("item");

    while(root)
    {
        string title = root->FirstChildElement("title")->GetText();
        string link = root->FirstChildElement("link")->GetText();
        string des = root->FirstChildElement("description")->GetText();
        string content = root->FirstChildElement("content:encoded")->GetText();

        //正则表达式
        regex rgx("<[^>]+>");
        des = std::regex_replace(des, rgx, "");
        content = std::regex_replace(content, rgx, "");

        cout << "title = " << title << endl;
        cout << "link = " << link << endl;
        cout << "des  = " << des << endl;
        cout << "content = " << content << endl;

        root = root->NextSiblingElement("item");//获取兄弟节点
    }

}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

